﻿#pragma once

#include "../MirControls/MirScene.h"
#include "../MirControls/MirImageControl.h"
#include "../MirControls/MirLabel.h"
#include "../MirControls/MirAnimatedControl.h"
#include "../MirControls/MirButton.h"
#include "../../Shared/Data/SharedData.h"
#include "../../Shared/Packet.h"
#include "../../Shared/ServerPackets.h"
#include "../MirControls/MirTextBox.h"
#include "../../Shared/Enums.h"
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <any>
#include "../../stringhelper.h"

//C# TO C++ CONVERTER NOTE: Forward class declarations:
namespace Client::MirScenes { class NewCharacterDialog; }
namespace Client::MirScenes { class CharacterButton; }

using namespace Client::MirControls;
using namespace Client::MirGraphics;
using namespace Client::MirNetwork;
using namespace Client::MirSounds;
namespace C = ClientPackets;
namespace S = ServerPackets;
namespace Client::MirScenes
{
    class SelectScene : public MirScene
    {

    public:
        MirImageControl *Background, *Title;
    private:
        NewCharacterDialog *_character;

    public:
        MirLabel *ServerLabel;
        MirAnimatedControl *CharacterDisplay;
        MirButton *StartGameButton, *NewCharacterButton, *DeleteCharacterButton, *CreditsButton, *ExitGame;
        std::vector<CharacterButton*> CharacterButtons;
        MirLabel *LastAccessLabel, *LastAccessLabelLabel;
        std::vector<SelectInfo*> Characters = std::vector<SelectInfo*>();
    private:
        int _selected = 0;

    public:
        virtual ~SelectScene()
        {
            delete Background;
            delete Title;
            delete _character;
            delete ServerLabel;
            delete CharacterDisplay;
            delete StartGameButton;
            delete NewCharacterButton;
            delete DeleteCharacterButton;
            delete CreditsButton;
            delete ExitGame;
            delete LastAccessLabel;
            delete LastAccessLabelLabel;
        }

        SelectScene(std::vector<SelectInfo*> &characters);

    private:
        void SelectScene_KeyPress(std::any sender, KeyPressEventArgs *e);


    public:
        void SortList();


        void StartGame();

        void Process() override;
        void ProcessPacket(Packet *p) override;

    private:
        void NewCharacter(S::NewCharacter *p);
        void NewCharacter(S::NewCharacterSuccess *p);

        void DeleteCharacter();

        void DeleteCharacter(S::DeleteCharacter *p);
        void DeleteCharacter(S::DeleteCharacterSuccess *p);

        void StartGame(S::StartGameDelay *p);
    public:
        void StartGame(S::StartGameBanned *p);
        void StartGame(S::StartGame *p);
    private:
        void UpdateInterface();


        #pragma region Disposable
    protected:
        void Dispose(bool disposing) override;
        #pragma endregion
    public:
        class NewCharacterDialog final : public MirImageControl
        {
        private:
            static Regex *const Reg;

        public:
            MirImageControl *TitleLabel;
            MirAnimatedControl *CharacterDisplay;

            MirButton *OKButton, *CancelButton, *WarriorButton, *WizardButton, *TaoistButton, *AssassinButton, *ArcherButton, *MaleButton, *FemaleButton;

            MirTextBox *NameTextBox;

            MirLabel *Description;

        private:
            MirClass _class = static_cast<MirClass>(0);
            MirGender _gender = static_cast<MirGender>(0);

            #pragma region Descriptions
        public:
            static const std::string WarriorDescription;

            static const std::string WizardDescription;

            static const std::string TaoistDescription;

            static const std::string AssassinDescription;

            static const std::string ArcherDescription;

            #pragma endregion

            virtual ~NewCharacterDialog()
            {
                delete TitleLabel;
                delete CharacterDisplay;
                delete OKButton;
                delete CancelButton;
                delete WarriorButton;
                delete WizardButton;
                delete TaoistButton;
                delete AssassinButton;
                delete ArcherButton;
                delete MaleButton;
                delete FemaleButton;
                delete NameTextBox;
                delete Description;
            }

            NewCharacterDialog();

        private:
            void TextBox_KeyPress(std::any sender, KeyPressEventArgs *e);
            void CharacterNameTextBox_TextChanged(std::any sender, EventArgs *e);

            void CreateCharacter();

            void UpdateInterface();
        };
    public:
        class CharacterButton final : public MirImageControl
        {
        public:
            MirLabel *NameLabel, *LevelLabel, *ClassLabel;
            bool Selected = false;

            virtual ~CharacterButton()
            {
                delete NameLabel;
                delete LevelLabel;
                delete ClassLabel;
            }

            CharacterButton();

            void Update(SelectInfo *info);
        };
    };
}
